﻿#region License
// Copyright © 2004 - 2010 All Right Reserved, Derek Goslin
// 
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
// 
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license
//     conditions and limitations in section 3, each contributor grants you a non-exclusive,
//     worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative 
//     works of its contribution, and distribute its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations
//     in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its
//     licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of
//     its contribution in the software or derivative works of the contribution in the software.
// 
// 3. Conditions and Limitations
// (A) Reciprocal Grants- For any file you distribute that contains code from the software (in source code or binary format), 
//     you must provide recipients the source code to that file along with a copy of this license, which license will govern that file. 
//     You may license other files that are entirely your own work and do not contain code from the software under any terms you choose.
// (B) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (C) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
//     your patent license from such contributor to the software ends automatically.
// (D) If you distribute any portion of the software, you must retain all copyright, patent, trademark,
//     and attribution notices that are present in the software.
// (E) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy 
//     of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do 
//     so under a license that complies with this license.
// (F) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions.
//    You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your
//    local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
#endregion

using System;

namespace DnEcuDiag.Conversion
{
    class MED711Conversion : Convertor, IConvertor
    {
        #region IConvertor Members

        public float Convert(int conversionId, byte[] rawData)
        {
            float result = 0;
            UInt32 rawValue = ConvertByteArray(rawData);

            switch (conversionId)
            {
                case 0:
                    result = rawValue;
                    break;
                case 700:
                    result = rawValue * 0.1f;
                    break;
                case 701:
                    result = rawValue;
                    break;
                case 702:
                    result = rawValue * 100;
                    break;
                case 703:
                    result = rawValue * 40;
                    break;
                case 704:
                    result = rawValue;
                    break;
                case 705:
                    result = rawValue * 0.1f;
                    break;
                case 706:
                    result = rawValue * 0.25f;
                    break;
                case 707:
                    result = (rawValue * 0.75f) - 48;
                    break;
                case 708:
                    result = (rawValue * 0.75f) - 48;
                    break;
                case 709:
                    result = rawValue * 0.1f;
                    break;
                case 710:
                    result = BitConverter.ToInt16(new[] { rawData[1], rawData[0] }, 0) * 0.75f;
                    break;
                case 711:
                    result = rawValue / 0.0032f;
                    break;
                case 712:
                    result = rawValue * 0.75f / 32;
                    break;
                case 713:
                    result = BitConverter.ToInt16(new[] { rawData[1], rawData[0] }, 0) * 0.0244f;
                    break;
                case 714:
                    result = rawValue * 0.1f;
                    break;
                case 716:
                    result = rawValue * 0.0757f;
                    break;
                case 717:
                    result = rawValue * 0.00781f;
                    break;
                case 718:
                    result = rawValue * 5f / 1024;
                    break;
                case 719:
                    result = rawValue * 5f / 1024;
                    break;
                case 720:
                    result = (rawValue * 5f / 1024) - 1;
                    break;
                case 721:
                    result = (rawValue * 5f / 1024) - 1;
                    break;
                case 722:
                    result = rawValue * 10;
                    break;
                case 723:
                    result = rawValue * 100f / 256;
                    break;
                case 725:
                    result = rawValue * 5f / 1024;
                    break;
                case 726:
                    result = rawValue * 5f / 1024;
                    break;
                case 727:
                    result = rawValue * 0.00152f;
                    break;
                case 728:
                    result = rawValue * 2f / 65536;
                    break;
                case 729:
                    result = rawValue * 2f / 65536;
                    break;
                case 730:
                    result = rawValue * 0.0468f;
                    break;
                case 731:
                    result = rawValue * 0.0468f;
                    break;
                case 732:
                    result = rawValue * 2f / 65536;
                    break;
                case 733:
                    result = rawValue * 2f / 65536;
                    break;
                case 734:
                    result = rawValue * 16f / 65536;
                    break;
                case 735:
                    result = rawValue * 16f / 65536;
                    break;
                case 736:
                    result = rawValue * 16f / 65536;
                    break;
                case 737:
                    result = rawValue * 16f / 65536;
                    break;
                case 738:
                    result = rawValue * 16f / 65536;
                    break;
                case 739:
                    result = rawValue * 16f / 65536;
                    break;
                case 742:
                    result = BitConverter.ToInt16(new[] { rawData[1], rawData[0] }, 0) * 100f / 32768;
                    break;
                case 743:
                    result = rawValue * 100f / 65536;
                    break;
                case 744:
                    result = rawValue * 4f / 65536;
                    break;
                case 745:
                    result = rawValue * 10f / 256;
                    break;
                case 746:
                    result = rawValue * 10f / 256;
                    break;
                case 747:
                    result = rawValue * 0.0039f;
                    break;
                case 748:
                    result = rawValue * 5f / 10000;
                    break;
                case 749:
                    result = rawValue * 5f / 10000;
                    break;
                case 750:
                    result = rawValue * 20f / 65536;
                    break;
                case 751:
                    result = rawValue * 100f / 65536;
                    break;
                case 752:
                    result = rawValue * 3f / 4;
                    break;
                case 753:
                    result = rawValue * 0.75f;
                    break;
                case 754:
                    result = rawValue * 0.1f;
                    break;
                case 755:
                    result = rawValue * 100f / 65536;
                    break;
                case 756:
                    result = rawValue * 200f / 65536;
                    break;
                case 757:
                    result = (rawValue * 5f) - 50;
                    break;
                case 758:
                    result = rawValue * 100f / 32768;
                    break;
                case 759:
                    result = rawValue * 64f / 65536;
                    break;
                case 760:
                    result = rawValue * 0.75f - 48;
                    break;
                case 761:
                    result = rawValue * 128f / 65536;
                    break;
                case 762:
                    result = rawValue * 0.1f;
                    break;
                case 763:
                    result = rawValue;
                    break;
                case 764:
                    result = (rawValue * 5f) - 50;
                    break;
                case 765:
                    result = rawValue * 0.75f;
                    break;
                case 766:
                    result = rawValue * 0.75f;
                    break;
                case 767:
                    result = rawValue / 255f * 100;
                    break;
                case 768:
                    result = rawValue * 0.0723f;
                    break;
                case 769:
                    result = rawValue * 40;
                    break;
                default:
                    break;
            }

            return result;
        }

        #endregion
    }
}
